
import 'dart:io';

import 'package:flutter/foundation.dart';
import 'package:path/path.dart';
import 'package:path_provider/path_provider.dart';
import 'package:uuid/uuid.dart';

Future<String> tempFile({@required String title,@required String suffix}) async {
  suffix ??= 'temp';
  if (!suffix.startsWith('.')) {
    suffix = '.$suffix';
  }
  var uuid = Uuid();
  String path;
  if (!kIsWeb) {
    Directory tmpDir = await getExternalStorageDirectory();

    tmpDir.list().toList().then((value) {
      print(value);
    });
    path = '${join(tmpDir.path, title)}$suffix';

    var parent = dirname(path);
    Directory(parent).createSync(recursive: true);
  } else {
    path = '$title$suffix';
  }
  return path;
}